package org.edu.modules.summary.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.summary.entity.VeCuzCourseSummary;
import org.edu.modules.summary.service.IVeCuzCourseSummaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@Api(tags={"课程简介"})
@RestController
@RequestMapping({"/course/veCuzCourseSummary"})
public class VeCuzCourseSummaryController
        extends BaseController<VeCuzCourseSummary, IVeCuzCourseSummaryService>
{
    private static final Logger log = LoggerFactory.getLogger(VeCuzCourseSummaryController.class);
    @Autowired
    private IVeCuzCourseSummaryService veCuzCourseSummaryService;

    @AutoLog("课程简介-分页列表查询")
    @ApiOperation(value="课程简介-分页列表查询", notes="课程简介-分页列表查询")
    @PostMapping({"/list"})
    public Result<?> queryPageList(VeCuzCourseSummary veCuzCourseSummary, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        QueryWrapper<VeCuzCourseSummary> queryWrapper = QueryGenerator.initQueryWrapper(veCuzCourseSummary, req.getParameterMap());
        Page<VeCuzCourseSummary> page = new Page(pageNo.intValue(), pageSize.intValue());
        IPage<VeCuzCourseSummary> pageList = this.veCuzCourseSummaryService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @AutoLog("课程简介-添加")
    @ApiOperation(value="课程简介-添加", notes="课程简介-添加")
    @PostMapping({"/add"})
    public Result<?> add(@RequestBody VeCuzCourseSummary veCuzCourseSummary)
    {
        this.veCuzCourseSummaryService.save(veCuzCourseSummary);
        return Result.OK("添加成功！");
    }

    @AutoLog("课程简介-编辑")
    @ApiOperation(value="课程简介-编辑", notes="课程简介-编辑")
    @PostMapping({"/edit"})
    public Result<?> edit(@RequestBody VeCuzCourseSummary veCuzCourseSummary)
    {
        this.veCuzCourseSummaryService.updateById(veCuzCourseSummary);
        return Result.OK("编辑成功!");
    }

    @AutoLog("课程简介-通过id删除")
    @ApiOperation(value="课程简介-通过id删除", notes="课程简介-通过id删除")
    @PostMapping({"/delete"})
    public Result<?> delete(@RequestParam(name="id", required=true) String id)
    {
        this.veCuzCourseSummaryService.removeById(id);
        return Result.OK("删除成功!");
    }

    @AutoLog("课程简介-批量删除")
    @ApiOperation(value="课程简介-批量删除", notes="课程简介-批量删除")
    @PostMapping({"/deleteBatch"})
    public Result<?> deleteBatch(@RequestParam(name="ids", required=true) String ids)
    {
        this.veCuzCourseSummaryService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    @AutoLog("课程简介-通过id查询")
    @ApiOperation(value="课程简介-通过id查询", notes="课程简介-通过id查询")
    @PostMapping({"/queryById"})
    public Result<?> queryById(@RequestParam(name="id", required=true) String id)
    {
        VeCuzCourseSummary veCuzCourseSummary = (VeCuzCourseSummary)this.veCuzCourseSummaryService.getById(id);
        if (veCuzCourseSummary == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(veCuzCourseSummary);
    }

    @RequestMapping({"/exportXls"})
    public ModelAndView exportXls(HttpServletRequest request, VeCuzCourseSummary veCuzCourseSummary)
    {
        return super.exportXls(request, veCuzCourseSummary, VeCuzCourseSummary.class, "课程简介");
    }

    @RequestMapping(value={"/importExcel"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response)
    {
        return super.importExcel(request, response, VeCuzCourseSummary.class);
    }
}
